<?php
namespace app\index\controller;
use app\index\model\Teacher;
use app\index\model\Student;

class Modify{

    public function modifyStudentPwd(){
        $res = input("post.");
        $student = Student::get($res["s_id"]);
        if ($student["pwd"]==md5($res["old_pwd"])){
            if($res["old_pwd"]!=$res["new_pwd"]){
                $student["pwd"]=md5($res["new_pwd"]);
                $student->save();
                return 1;
            }else{
                return 2;
            }
        }else{
            return 3;
        }

        return $res;
    }

    public function modifyTeacherPwd(){
        $res = input("post.");
        $teacher = Teacher::get($res["t_id"]);
        if ($teacher["pwd"]==md5($res["old_pwd"])){
            if($res["old_pwd"]!=$res["new_pwd"]){
                $teacher["pwd"]=md5($res["new_pwd"]);
                $teacher->save();
                return 1;
            }else{
                return 2;
            }
        }else{
            return 3;
        }

        return $res;
    }
}